package com.handpay.framework.utils;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

/**
 * @author yanglun E-mail:sunshine_yangl@sina.com
 * @version 2015-11-4 下午2:25:27
 */
public class BitmapLoaderNew {
	private static BitmapLoaderNew mInstance;

	public static BitmapLoaderNew getInstance(Context context) {
		if (null == mInstance) {
			mInstance = new BitmapLoaderNew();
			ImageLoaderConfiguration configuration = ImageLoaderConfiguration
					.createDefault(context);
			ImageLoader.getInstance().init(configuration);

		}
		return mInstance;
	}

	public void loadImage(String uri, ImageView iv) {

		DisplayImageOptions options = new DisplayImageOptions.Builder()
		// .showImageOnLoading(R.drawable.ic_stub) //加载图片时的图片
		// .showImageForEmptyUri(R.drawable.ic_empty) //没有图片资源时的默认图片
		// .showImageOnFail(R.drawable.ic_error) //加载失败时的图片
				.cacheInMemory(true) // 启用内存缓存
				.cacheOnDisk(true) // 启用外存缓存
				.considerExifParams(true) // 启用EXIF和JPEG图像格式
				// .displayer(new RoundedBitmapDisplayer(20)) //设置显示风格这里是圆角矩形
				.build();
		ImageLoader.getInstance().displayImage(uri, iv, options);
	}

	public void loadImage(String uri,
			BitmapLoaderListener listener) {

		DisplayImageOptions options = new DisplayImageOptions.Builder()
				.cacheInMemory(true) // 启用内存缓存
				.cacheOnDisk(true) // 启用外存缓存
				.considerExifParams(true) // 启用EXIF和JPEG图像格式
				.build();
//		ImageLoader.getInstance().displayImage(uri, iv, options,listener);
		
		ImageLoader.getInstance().loadImage(uri, options, listener);
	}

	
	
	
	abstract static public class BitmapLoaderListener implements
			ImageLoadingListener {
		@Override
		public void onLoadingStarted(String imageUri, View view) {

		}

		@Override
		public void onLoadingFailed(String imageUri, View view,
				FailReason failReason) {

		}

		@Override
		public void onLoadingCancelled(String imageUri, View view) {

		}
	}

}